﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Data.SqlClient;

namespace Final.App_Code
{
    public class login
    {

        private string User;
        private string Password;

        public string user
        {
            get { return user; }
            set { user = value; }
        }
        public string password
        {
            get { return password; }
            set { password = value; }
        }
        public login(string user, string password)
        {
            this.user = user;
            this.password = password;
        }

        public login()
        {
            // TODO: Complete member initialization
        }

        public static login Login_Acc(string user, string password)
        {
            SqlConnection conn = null;
            login b = null;
            try
            {
                conn = new SqlConnection();
                conn.ConnectionString = ConfigurationManager.ConnectionStrings["SubjectManagementDBString"].ConnectionString;
                SqlCommand comm = new SqlCommand();
                conn.Open();
                comm.Connection = conn;
                comm.CommandText = "SELECT id, Password FROM Account WHERE user=@id AND Password=@Password";
                comm.Parameters.AddWithValue("@id", user);
                comm.Parameters.AddWithValue("@Password", password);
                SqlDataReader dr = comm.ExecuteReader();

                if (dr.Read())
                {
                    b = new login();
                    b.user = (String)dr["id"];
                    b.password = (String)dr["Password"];
                }
                dr.Close();
            }
            catch (SqlException e)
            {
                throw e;
            }
            finally
            {
                conn.Close();
            }

            return b;

        }
    }
}